object t4 {
  def isPalindrome(word: String): Boolean = {
    val cleanWord = word.toLowerCase
    cleanWord == cleanWord.reverse
  }

  def filterPalindromes(text: String): List[String] = {
    text.split("\\s+").filter(isPalindrome).toList
  }

  def main(args: Array[String]): Unit = {

    val text = "madam level apple racecar noon"
    val palindromes = filterPalindromes(text)
    println(s"Palindromes in text: $palindromes")

  }
}
